﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microformats.Controls;
using System.Web.UI;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace Microformats.Controls
{
    public class Location : CalendarProperty
    {
        public Location()
        {
            ClassName = "location";
            Locations = new LocationAddresses();
        }

        public string Value { get; set; }

        [Browsable(true)]
        [Category("Calendar Parameter")]
        [Description("Specifies the calendar location properties.")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public LocationAddresses Locations
        {
            get;
            set;
        }

        public void Render(ref HtmlTextWriter writer)
        {
            if (this.Locations.Addresses.Count() > 0)
            {
                foreach (Address address in this.Locations.Addresses)
                {
                    address.Render(ref writer);
                }
            }
            else if (!string.IsNullOrEmpty(this.Value))
            {
                if (string.IsNullOrEmpty(Format))
                {
                    writer.WriteLine();
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, this.ClassName);
                    writer.RenderBeginTag(this.HtmlTag);
                    writer.Write(this.Value);
                    writer.RenderEndTag();
                }
            }
        }
    }
}
